package top.wshape1.rpc.common.entity;

import lombok.Data;
import top.wshape1.rpc.common.constant.RoleType;
import top.wshape1.rpc.config.JJRpcConfig;

import java.io.Serializable;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2024-02-02
 */

@Data
public class ServiceMeta implements Serializable {

    /**
     * 服务名，服务接口的全类名
     */
    private String serviceName;

    private String ip;

    private int port;

    private RoleType role;

    public String getAddress() {
        return ip + ":" + port;
    }

    public void setAddress(String address) {
        String[] split = address.split(":");
        this.ip = split[0];
        this.port = Integer.parseInt(split[1]);
    }

    public static ServiceMeta selfServiceMeta(String serviceName, RoleType role) {
        ServiceMeta serviceMeta = new ServiceMeta();
        serviceMeta.setServiceName(serviceName);
        serviceMeta.setRole(role);
        serviceMeta.setIp(JJRpcConfig.CONFIG.getHost());
        serviceMeta.setPort(JJRpcConfig.CONFIG.getPort());
        return serviceMeta;
    }

    private static final long serialVersionUID = 1L;


}
